package com.example.myshopping3.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 生成订单
 */
public class OrderId {
    private static final int MIN = 0;
    private static final int MAX = 10000;
    private static int num = MIN;

    //想想为什么要加同步锁
    public synchronized static String getOrderId() {
        //根据当前时间生成一个时间序列(年月日时分秒毫秒)
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSS");
        String nowTimeStr = format.format(new Date());
        if (num > MAX) {
            num = MIN;
        }
        String orderId = nowTimeStr + num;
        return orderId;
    }


}
